package com.hzhr.iot.web.controller;

import com.hzhr.iot.core.util.HzhrDateUtil;
import com.hzhr.iot.core.util.HzhrStringUtils;
import com.hzhr.iot.device.sdk.service.Device_CollectDeviceService;
import com.hzhr.iot.login.sdk.model.userCard.UserCardModel;
import com.hzhr.iot.statis.sdk.model.deptMonthlyGasConsume.dataSum.DeptMonthlyGasConsumeDataSumModel;
import com.hzhr.iot.statis.sdk.model.deptMonthlyGasConsume.monthDataSum.DeptMonthlyGasConsumeMonthDataSumModel;
import com.hzhr.iot.statis.sdk.model.gasUserDailyGasConsume.GasUserDailyGasConsumeModel;
import com.hzhr.iot.statis.sdk.model.gasUserDailyGasConsume.dayDataSum.GasUserDailyGasConsumeDayDataSumModel;
import com.hzhr.iot.statis.sdk.service.Statis_DeptDailyGasConsumeService;
import com.hzhr.iot.statis.sdk.service.Statis_DeptMonthlyGasConsumeService;
import com.hzhr.iot.statis.sdk.service.Statis_DeviceDataExceptionService;
import com.hzhr.iot.statis.sdk.service.Statis_GasUserDailyGasConsumeService;
import com.hzhr.iot.toll.sdk.model.gasUser_basicInfo.GasUser_BasicInfoModel;
import com.hzhr.iot.toll.sdk.service.Toll_GasUserService;
import com.hzhr.iot.toll.sdk.service.Toll_GasUser_BasicInfoService;
import com.hzhr.iot.web.Global;
import com.hzhr.iot.web.constant.DeviceOptions;
import com.hzhr.iot.web.constant.TollOptions;
import com.hzhr.iot.web.controller.base.BaseController;
import com.hzhr.iot.web.model.response.BaseResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.*;

@RequestMapping("/report")
@Api(description = "大屏报表")
@RestController
public class ReportController extends BaseController {
    @Autowired
    Device_CollectDeviceService device_collectDeviceService;
    @Autowired
    DeviceOptions deviceOptions;
    @Autowired
    Statis_DeptMonthlyGasConsumeService statis_deptMonthlyGasConsumeService;
    @Autowired
    Toll_GasUserService toll_gasUserService;
    @Autowired
    Statis_GasUserDailyGasConsumeService statis_gasUserDailyGasConsumeService;
    @Autowired
    TollOptions tollOptions;
    @Autowired
    Toll_GasUser_BasicInfoService toll_gasUser_basicInfoService;
    @Autowired
    Global global;
    @Autowired
    Statis_DeptDailyGasConsumeService statis_deptDailyGasConsumeService;
    @Autowired
    Statis_DeviceDataExceptionService statis_deviceDataExceptionService;



    @ApiOperation(value = "昨日设备数量", notes = "昨日设备数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uat", value = "用户登录令牌", dataType = "String", required = true, paramType = "query"),
    })
    @RequestMapping(value = "/getcollectdevice", method = RequestMethod.POST)
    BaseResponse getcollectdevice(
                         @RequestParam(value = "uat", required = true) String uat) throws Exception {
        String token = getToken();
        Map<String, String> header = new HashMap<String, String>();
        header.put("token", token);
        Map<String, Object> query = new HashMap<String, Object>();
        query.put("show_total", Boolean.valueOf(true));
        query.put("greaterthanorequal_createTime", Long.valueOf(HzhrDateUtil.getBeginDayOfMonth().getTime()));

        String gprsCategoryCode = this.deviceOptions.getCode("COLLECT_DEVICE_CATEGORY", "GPRS_IOT_GAS_METER");
        query.put("equal_categoryCode", gprsCategoryCode);
        int gprsCount = this.device_collectDeviceService.get(header, query).getTotal().intValue();

        String loraCategoryCode = this.deviceOptions.getCode("COLLECT_DEVICE_CATEGORY", "LORA_METER");
        query.put("equal_categoryCode", loraCategoryCode);
        int loraCount = this.device_collectDeviceService.get(header, query).getTotal().intValue();

        String nbCategoryCode = this.deviceOptions.getCode("COLLECT_DEVICE_CATEGORY", "NB_IOT_GAS_METER");
        query.put("equal_categoryCode", nbCategoryCode);
        int nbCount = this.device_collectDeviceService.get(header, query).getTotal().intValue();

        String pressureCategoryCode = this.deviceOptions.getCode("COLLECT_DEVICE_CATEGORY", "GAS_PRESSURE_MONITOR");
        query.put("equal_categoryCode", pressureCategoryCode);
        int pressureCount = this.device_collectDeviceService.get(header, query).getTotal().intValue();

        String flowCategoryCode = this.deviceOptions.getCode("COLLECT_DEVICE_CATEGORY", "FLOW_METER");
        query.put("equal_categoryCode", flowCategoryCode);
        int flowCount = this.device_collectDeviceService.get(header, query).getTotal().intValue();

        String bkCategoryCode = this.deviceOptions.getCode("COLLECT_DEVICE_CATEGORY", "BK_METER");
        query.put("equal_categoryCode", bkCategoryCode);
        int bkCount = this.device_collectDeviceService.get(header, query).getTotal().intValue();


        HashMap<String, Integer> result = new HashMap<String, Integer>();
        result.put("NB物联网表", Integer.valueOf(nbCount));
        result.put("GPRS物联网表", Integer.valueOf(gprsCount));
        result.put("LORA无线远传表", Integer.valueOf(loraCount));
        result.put("BK表", Integer.valueOf(bkCount));
        result.put("流量计", Integer.valueOf(flowCount));
        result.put("燃气管网压力监测仪", Integer.valueOf(pressureCount));
        result.put("泄漏报警器", Integer.valueOf(0));
        result.put("调压设备", Integer.valueOf(1));
        return new BaseResponse("0", "成功", result);

    }

    @ApiOperation(value = "改造设备概况", notes = "改造设备概况")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uat", value = "用户登录令牌", dataType = "String", required = true, paramType = "query"),
    })
    @RequestMapping(value = "/devicegasconsume", method = RequestMethod.POST)
    BaseResponse devicegasconsume(
            @RequestParam(value = "uat", required = true) String uat) throws Exception {
        String token = getToken();
        Map<String, String> header = new HashMap<String, String>();
        header.put("token", token);
        Map<String, Object> query = new HashMap<String, Object>();
        query.put("show_total", Boolean.valueOf(true));

        String gprsCategoryCode = this.deviceOptions.getCode("COLLECT_DEVICE_CATEGORY", "GPRS_IOT_GAS_METER");
        query.put("equal_categoryCode", gprsCategoryCode);
        int gprsCount = this.device_collectDeviceService.get(header, query).getTotal().intValue();

        String loraCategoryCode = this.deviceOptions.getCode("COLLECT_DEVICE_CATEGORY", "LORA_METER");
        query.put("equal_categoryCode", loraCategoryCode);
        int loraCount = this.device_collectDeviceService.get(header, query).getTotal().intValue();

        String nbCategoryCode = this.deviceOptions.getCode("COLLECT_DEVICE_CATEGORY", "NB_IOT_GAS_METER");
        query.put("equal_categoryCode", nbCategoryCode);
        int nbCount = this.device_collectDeviceService.get(header, query).getTotal().intValue();

        String pressureCategoryCode = this.deviceOptions.getCode("COLLECT_DEVICE_CATEGORY", "GAS_PRESSURE_MONITOR");
        query.put("equal_categoryCode", pressureCategoryCode);
        int pressureCount = this.device_collectDeviceService.get(header, query).getTotal().intValue();

        String flowCategoryCode = this.deviceOptions.getCode("COLLECT_DEVICE_CATEGORY", "FLOW_METER");
        query.put("equal_categoryCode", flowCategoryCode);
        int flowCount = this.device_collectDeviceService.get(header, query).getTotal().intValue();

        String bkCategoryCode = this.deviceOptions.getCode("COLLECT_DEVICE_CATEGORY", "BK_METER");
        query.put("equal_categoryCode", bkCategoryCode);
        int bkCount = this.device_collectDeviceService.get(header, query).getTotal().intValue();

        HashMap<String, Integer> result = new HashMap<String, Integer>();
        result.put("NB物联网表", Integer.valueOf(nbCount));
        result.put("GPRS物联网表", Integer.valueOf(gprsCount));
        result.put("LORA无线远传表", Integer.valueOf(loraCount));
        result.put("BK表", Integer.valueOf(bkCount));
        result.put("燃气管网压力监测仪", Integer.valueOf(pressureCount));
        result.put("流量计", Integer.valueOf(flowCount));
        result.put("泄漏报警器", Integer.valueOf(0));
        result.put("调压设备", Integer.valueOf(1));
        return new BaseResponse("0", "成功", result);
    }

    @ApiOperation(value = "7天用户用气量", notes = "7天用户用气量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uat", value = "用户登录令牌", dataType = "String", required = true, paramType = "query"),
            @ApiImplicitParam(name = "gasusertype", value = "用户类型 1.居民用户 2工商用户", dataType = "int", required = true, paramType = "query")
    })
    @RequestMapping(value = "/sevendaygasconsume", method = RequestMethod.POST)
    BaseResponse sevendaygasconsume(
            @RequestParam(value = "uat", required = true) String uat,
            @RequestParam(value = "gasusertype", required = true,defaultValue = "1") int gasusertype) throws Exception {
        Map<String,Object> result=new HashMap<>();
        Map<String, Object> result1 = new HashMap<>();
        Map<String, Object> resultgasusertype = new HashMap<>();
        result.put("result", result1);
        result.put("resultgasusertype", resultgasusertype);
        Date date = HzhrDateUtil.getDayBegin();
        Date date1 = HzhrDateUtil.addDay(date, -1);
        Date date2 = HzhrDateUtil.addDay(date, -7);

        //大用户
        Map<String, String> header = new HashMap<>();
        String token = getToken();
        header.put("token", token);
        Map<String, Object> query = new HashMap<>();
        query.put("greaterthanorequal_date", date1.getTime());
        query.put("orderBy_data", "desc");
        query.put("page", 1);
        query.put("count", 4);
        query.put("show", "list");
        query.put("show_info", true);
        String residentialGasUserType = tollOptions.getCode("GAS_USER_TYPE", "RESIDENTIAL_USER");
        String commercialGasUserType = tollOptions.getCode("GAS_USER_TYPE", "COMMERCIAL_USER");
        if (gasusertype == 1) {
            query.put("equal_gasUserType", residentialGasUserType);
        } else if (gasusertype == 2) {
            query.put("equal_gasUserType", commercialGasUserType);
        }
        List<GasUserDailyGasConsumeModel> gasUserDailyGasConsumeModels = statis_gasUserDailyGasConsumeService.get(header, query).getModelList();
        List<Integer> gasUserIds = new ArrayList<>();
        for (GasUserDailyGasConsumeModel gasUserDailyGasConsumeModel :
        gasUserDailyGasConsumeModels) {
            gasUserIds.add(gasUserDailyGasConsumeModel.getGasUserId());
        }
        if (gasUserIds.size() > 0) {
            Map<String, String> header1 = new HashMap<>();
            header1.put("token", global.getToken());
            Map<String, Object> query1 = new HashMap<>();
            query1.put("_in_id", gasUserIds);
            query1.put("_show", "list");
            query1.put("_show_info", true);
            List<GasUser_BasicInfoModel> gasUser_basicInfoModels = toll_gasUser_basicInfoService.get1(header1, query1).getModelList();
            for (GasUserDailyGasConsumeModel gasUserDailyGasConsumeModel :
                    gasUserDailyGasConsumeModels) {
                for (GasUser_BasicInfoModel gasUser_basicInfoModel :
                gasUser_basicInfoModels) {
                    if (gasUserDailyGasConsumeModel.getGasUserId().equals(gasUser_basicInfoModel.getId())) {
                        Double data =  gasUserDailyGasConsumeModel.getData();
                        if (gasusertype == 1) {
                            BigDecimal b = new BigDecimal(data).setScale(1, BigDecimal.ROUND_UP);
                            resultgasusertype.put(gasUser_basicInfoModel.getName(), b.doubleValue());
                        } else if (gasusertype == 2) {
                            BigDecimal b = new BigDecimal(data).divide(new BigDecimal(10000), 3, BigDecimal.ROUND_UP);
                            resultgasusertype.put(gasUser_basicInfoModel.getName(), b.doubleValue());
                        }
                        break;
                    }
                }
            }
        }

        //七天用气情况
        UserCardModel userCard = getUserCard(token);
        Map<String, String> header2 = new HashMap<>();
        header2.put("token", global.getFirstToken());
        Map<String, Object> query2 = new HashMap<>();
        query2.put("_deptId", userCard.getDeptId());
        if (gasusertype == 1) {
            query2.put("_equal_gasUserType", residentialGasUserType);
        } else if (gasusertype == 2) {
            query2.put("_equal_gasUserType", commercialGasUserType);
        }
        query2.put("_greaterthanorequal_date", date2.getTime());
        query2.put("_lessthan_date", date.getTime());
        GasUserDailyGasConsumeDayDataSumModel gasUserDailyGasConsumeDayDataSumModel = statis_gasUserDailyGasConsumeService.getDayDataSum(header2, query2);
        List<String> dayList = gasUserDailyGasConsumeDayDataSumModel.getDayList();
        List<Double> dataSumList = gasUserDailyGasConsumeDayDataSumModel.getDataSumList();
        Double sum = 0.0;
        for (int i = 0; i < dayList.size(); i++) {
            String day = dayList.get(i);
            Double dataSum = dataSumList.get(i);
            if (gasusertype == 1) {
                result1.put(day, new BigDecimal(dataSum).setScale(1, BigDecimal.ROUND_UP).doubleValue());
            } else if (gasusertype == 2) {
                result1.put(day, new BigDecimal(dataSum).divide(new BigDecimal(10000), 3, BigDecimal.ROUND_UP).doubleValue());
            }
            if (dataSum != null) sum += dataSum;
        }
        if (gasusertype == 1) {
            result.put("allcount", new BigDecimal(sum).setScale(1, BigDecimal.ROUND_UP).doubleValue());
        } else if (gasusertype == 2) {
            result.put("allcount", new BigDecimal(sum).divide(new BigDecimal(10000), 3, BigDecimal.ROUND_UP).doubleValue());
        }


        return new BaseResponse("0", "成功",result);
    }

    @ApiOperation(value = "年用气量", notes = "年用气量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uat", value = "用户登录令牌", dataType = "String", required = true, paramType = "query")
    })
    @RequestMapping(value = "/yeargasconsume", method = RequestMethod.POST)
    BaseResponse yeargasconsume(
            @RequestParam(value = "uat", required = true) String uat) throws Exception {
        HashMap<String,Object> result = new LinkedHashMap<>();

        String token = getToken();
        UserCardModel userCard = getUserCard(token);
        Map<String, String> header2 = new HashMap<>();
        header2.put("token", global.getFirstToken());
        Map<String, Object> query2 = new HashMap<>();
        query2.put("_deptId", userCard.getDeptId());
        query2.put("_greaterthanorequal_date", HzhrDateUtil.getBeginDayOfYear().getTime());
        query2.put("_lessthan_date", new Date().getTime());
        DeptMonthlyGasConsumeMonthDataSumModel deptMonthlyGasConsumeMonthDataSumModel = statis_deptMonthlyGasConsumeService.getMonthDataSum(header2, query2);
        List<String> monthList = deptMonthlyGasConsumeMonthDataSumModel.getMonthList();
        List<Double> dataSumList = deptMonthlyGasConsumeMonthDataSumModel.getDataSumList();
        for (int i = 1; i <= 12; i ++) {
            String monthStr = HzhrDateUtil.dateToStr(new Date(), "yyyy") + "-" + HzhrStringUtils.fillZeroForLeft(i + "", 2);
            for (int j = 0; j < monthList.size(); j++) {
                String month = monthList.get(j);
                if (monthStr.equals(month)) {
                    Double dataSum = dataSumList.get(j);
                    result.put(month, new BigDecimal(dataSum).divide(new BigDecimal(10000), 2, BigDecimal.ROUND_UP).doubleValue());
                    break;
                }
            }
            if (result.get(monthStr) == null) {
                result.put(monthStr, "0.00");
            }
        }

        return new BaseResponse("0", "成功",result);
    }

    @ApiOperation(value = "设备异常统计", notes = "设备异常统计")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uat", value = "用户登录令牌", dataType = "String", required = true, paramType = "query")
    })
    @RequestMapping(value = "/alarmdata", method = RequestMethod.POST)
    BaseResponse alarmdata(
            @RequestParam(value = "uat", required = true) String uat) throws Exception {
        Map<String,Object> result=new HashMap<>();
        Map<String,Object> item2 = new HashMap<>();
        result.put("GPRS物联网表", item2);
        Map<String,Object> item3 = new HashMap<>();
        result.put("LORA无线远传表", item3);
        Map<String,Object> item4 = new HashMap<>();
        result.put("NB物联网表", item4);
        Map<String,Object> item5 = new HashMap<>();
        result.put("BK表", item5);
        Map<String,Object> item6 = new HashMap<>();
        result.put("流量计", item6);

        Map<String, String> header = new HashMap<>();
        header.put("token", getToken());
        Map<String, Object> query = new HashMap<>();
        query.put("equal_statisDate", HzhrDateUtil.getDayBegin().getTime());
        query.put("show_total", true);

        String code = deviceOptions.getCode("COLLECT_DEVICE_CATEGORY", "GPRS_IOT_GAS_METER");
        query.put("equal_collectDeviceCategoryCode", code);
        query.put("greaterthanorequal_exceptionDayCount", 3);
        query.put("equal_exceptionType", "1");
        int total = statis_deviceDataExceptionService.get(header, query).getTotal();
        item2.put("昨日未上传", total);
        query.put("greaterthanorequal_exceptionDayCount", 30);
        total = statis_deviceDataExceptionService.get(header, query).getTotal();
        item2.put("七天未上传", total);
        query.put("greaterthanorequal_exceptionDayCount", 3);
        query.put("equal_exceptionType", "2");
        total = statis_deviceDataExceptionService.get(header, query).getTotal();
        item2.put("昨日未用气", total);
        query.put("greaterthanorequal_exceptionDayCount", 30);
        total = statis_deviceDataExceptionService.get(header, query).getTotal();
        item2.put("七天未用气", total);

        code = deviceOptions.getCode("COLLECT_DEVICE_CATEGORY", "LORA_METER");
        query.put("equal_collectDeviceCategoryCode", code);
        query.put("greaterthanorequal_exceptionDayCount", 3);
        query.put("equal_exceptionType", "1");
        total = statis_deviceDataExceptionService.get(header, query).getTotal();
        item3.put("昨日未上传", total);
        query.put("greaterthanorequal_exceptionDayCount", 30);
        total = statis_deviceDataExceptionService.get(header, query).getTotal();
        item3.put("七天未上传", total);
        query.put("greaterthanorequal_exceptionDayCount", 3);
        query.put("equal_exceptionType", "2");
        total = statis_deviceDataExceptionService.get(header, query).getTotal();
        item3.put("昨日未用气", total);
        query.put("greaterthanorequal_exceptionDayCount", 30);
        total = statis_deviceDataExceptionService.get(header, query).getTotal();
        item3.put("七天未用气", total);

        code = deviceOptions.getCode("COLLECT_DEVICE_CATEGORY", "NB_IOT_GAS_METER");
        query.put("equal_collectDeviceCategoryCode", code);
        query.put("greaterthanorequal_exceptionDayCount", 3);
        query.put("equal_exceptionType", "1");
        total = statis_deviceDataExceptionService.get(header, query).getTotal();
        item4.put("昨日未上传", total);
        query.put("greaterthanorequal_exceptionDayCount", 30);
        total = statis_deviceDataExceptionService.get(header, query).getTotal();
        item4.put("七天未上传", total);
        query.put("greaterthanorequal_exceptionDayCount", 3);
        query.put("equal_exceptionType", "2");
        total = statis_deviceDataExceptionService.get(header, query).getTotal();
        item4.put("昨日未用气", total);
        query.put("greaterthanorequal_exceptionDayCount", 30);
        total = statis_deviceDataExceptionService.get(header, query).getTotal();
        item4.put("七天未用气", total);

        code = deviceOptions.getCode("COLLECT_DEVICE_CATEGORY", "BK_METER");
        query.put("equal_collectDeviceCategoryCode", code);
        query.put("greaterthanorequal_exceptionDayCount", 3);
        query.put("equal_exceptionType", "1");
        total = statis_deviceDataExceptionService.get(header, query).getTotal();
        item5.put("昨日未上传", total);
        query.put("greaterthanorequal_exceptionDayCount", 30);
        total = statis_deviceDataExceptionService.get(header, query).getTotal();
        item5.put("七天未上传", total);
        query.put("greaterthanorequal_exceptionDayCount", 3);
        query.put("equal_exceptionType", "2");
        total = statis_deviceDataExceptionService.get(header, query).getTotal();
        item5.put("昨日未用气", total);
        query.put("greaterthanorequal_exceptionDayCount", 30);
        total = statis_deviceDataExceptionService.get(header, query).getTotal();
        item5.put("七天未用气", total);

        code = deviceOptions.getCode("COLLECT_DEVICE_CATEGORY", "FLOW_METER");
        query.put("equal_collectDeviceCategoryCode", code);
        query.put("greaterthanorequal_exceptionDayCount", 3);
        query.put("equal_exceptionType", "1");
        total = statis_deviceDataExceptionService.get(header, query).getTotal();
        item6.put("昨日未上传", total);
        query.put("greaterthanorequal_exceptionDayCount", 30);
        total = statis_deviceDataExceptionService.get(header, query).getTotal();
        item6.put("七天未上传", total);
        query.put("greaterthanorequal_exceptionDayCount", 3);
        query.put("equal_exceptionType", "2");
        total = statis_deviceDataExceptionService.get(header, query).getTotal();
        item6.put("昨日未用气", total);
        query.put("greaterthanorequal_exceptionDayCount", 30);
        total = statis_deviceDataExceptionService.get(header, query).getTotal();
        item6.put("七天未用气", total);

        return new BaseResponse("0", "成功",result);
    }

    @ApiOperation(value = "数据总概", notes = "数据总概")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uat", value = "用户登录令牌", dataType = "String", required = true, paramType = "query")
    })
    @RequestMapping(value = "/totalofquantities", method = RequestMethod.POST)
    BaseResponse totalofquantities(@RequestParam(value = "uat", required = true) String uat)throws Exception {
        String token = getToken();
        Map<String, String> header = new HashMap<String, String>();
        header.put("token", token);
        Map<String, Object> query = new HashMap<String, Object>();
        query.put("show_total", Boolean.valueOf(true));
        int collectdevicecount = this.device_collectDeviceService.get(header, query).getTotal().intValue();

        query = new HashMap<String, Object>();
        query.put("greaterthanorequal_date", Long.valueOf(HzhrDateUtil.getBeginDayOfMonth().getTime()));
        DeptMonthlyGasConsumeDataSumModel dataSumModel = this.statis_deptMonthlyGasConsumeService.getDataSum(header, query);
        Double monthgascount = dataSumModel.getDataSum();
        BigDecimal b1 = (monthgascount != null) ? (new BigDecimal(monthgascount.doubleValue())).divide(new BigDecimal('?'), 1) : new BigDecimal(0);

        query = new HashMap<String, Object>();
        dataSumModel = this.statis_deptMonthlyGasConsumeService.getDataSum(header, query);
        Double yeargascount = dataSumModel.getDataSum();
        BigDecimal b2 = (yeargascount != null) ? (new BigDecimal(yeargascount.doubleValue())).divide(new BigDecimal('?'), 0) : new BigDecimal(0);

        HashMap<String, String> result = new HashMap<String, String>();
        result.put("collectdevicecount", (new StringBuilder(String.valueOf(collectdevicecount))).toString());
        result.put("monthgascount", (new StringBuilder(String.valueOf(b1.doubleValue()))).toString());
        result.put("yeargascount", (new StringBuilder(String.valueOf(b2.doubleValue()))).toString());

        int sanririweishanchuang = 0;
        int sanriweiyongqi = 0;
        int sanshiriweishanchuang = 0;
        int sanshiriweiyongqi = 0;
        header = new HashMap<String, String>();
        header.put("token", getToken());
        query = new HashMap<String, Object>();
        query.put("equal_statisDate", Long.valueOf(HzhrDateUtil.getDayBegin().getTime()));
        query.put("show_total", Boolean.valueOf(true));
        String code = this.deviceOptions.getCode("COLLECT_DEVICE_CATEGORY", "GPRS_IOT_GAS_METER");
        query.put("equal_collectDeviceCategoryCode", code);
        query.put("greaterthanorequal_exceptionDayCount", Integer.valueOf(3));
        query.put("equal_exceptionType", "1");
        int total = this.statis_deviceDataExceptionService.get(header, query).getTotal().intValue();
        sanririweishanchuang += total;
        query.put("greaterthanorequal_exceptionDayCount", Integer.valueOf(30));
        total = this.statis_deviceDataExceptionService.get(header, query).getTotal().intValue();
        sanshiriweishanchuang += total;
        query.put("greaterthanorequal_exceptionDayCount", Integer.valueOf(3));
        query.put("equal_exceptionType", "2");
        total = this.statis_deviceDataExceptionService.get(header, query).getTotal().intValue();
        sanriweiyongqi += total;
        query.put("greaterthanorequal_exceptionDayCount", Integer.valueOf(30));
        total = this.statis_deviceDataExceptionService.get(header, query).getTotal().intValue();
        sanshiriweiyongqi += total;
        code = this.deviceOptions.getCode("COLLECT_DEVICE_CATEGORY", "NB_IOT_GAS_METER");
        query.put("equal_collectDeviceCategoryCode", code);
        query.put("greaterthanorequal_exceptionDayCount", Integer.valueOf(3));
        query.put("equal_exceptionType", "1");
        total = this.statis_deviceDataExceptionService.get(header, query).getTotal().intValue();
        sanririweishanchuang += total;
        query.put("greaterthanorequal_exceptionDayCount", Integer.valueOf(30));
        total = this.statis_deviceDataExceptionService.get(header, query).getTotal().intValue();
        sanshiriweishanchuang += total;
        query.put("greaterthanorequal_exceptionDayCount", Integer.valueOf(3));
        query.put("equal_exceptionType", "2");
        total = this.statis_deviceDataExceptionService.get(header, query).getTotal().intValue();
        sanriweiyongqi += total;
        query.put("greaterthanorequal_exceptionDayCount", Integer.valueOf(30));
        total = this.statis_deviceDataExceptionService.get(header, query).getTotal().intValue();
        sanshiriweiyongqi += total;
        code = this.deviceOptions.getCode("COLLECT_DEVICE_CATEGORY", "BK_METER");
        query.put("equal_collectDeviceCategoryCode", code);
        query.put("greaterthanorequal_exceptionDayCount", Integer.valueOf(3));
        query.put("equal_exceptionType", "1");
        total = this.statis_deviceDataExceptionService.get(header, query).getTotal().intValue();
        sanririweishanchuang += total;
        query.put("greaterthanorequal_exceptionDayCount", Integer.valueOf(30));
        total = this.statis_deviceDataExceptionService.get(header, query).getTotal().intValue();
        sanshiriweishanchuang += total;
        query.put("greaterthanorequal_exceptionDayCount", Integer.valueOf(3));
        query.put("equal_exceptionType", "2");
        total = this.statis_deviceDataExceptionService.get(header, query).getTotal().intValue();
        sanriweiyongqi += total;
        query.put("greaterthanorequal_exceptionDayCount", Integer.valueOf(30));
        total = this.statis_deviceDataExceptionService.get(header, query).getTotal().intValue();
        sanshiriweiyongqi += total;
        code = this.deviceOptions.getCode("COLLECT_DEVICE_CATEGORY", "FLOW_METER");
        query.put("equal_collectDeviceCategoryCode", code);
        query.put("greaterthanorequal_exceptionDayCount", Integer.valueOf(3));
        query.put("equal_exceptionType", "1");
        total = this.statis_deviceDataExceptionService.get(header, query).getTotal().intValue();
        sanririweishanchuang += total;
        query.put("greaterthanorequal_exceptionDayCount", Integer.valueOf(30));
        total = this.statis_deviceDataExceptionService.get(header, query).getTotal().intValue();
        sanshiriweishanchuang += total;
        query.put("greaterthanorequal_exceptionDayCount", Integer.valueOf(3));
        query.put("equal_exceptionType", "2");
        total = this.statis_deviceDataExceptionService.get(header, query).getTotal().intValue();
        sanriweiyongqi += total;
        query.put("greaterthanorequal_exceptionDayCount", Integer.valueOf(30));
        total = this.statis_deviceDataExceptionService.get(header, query).getTotal().intValue();
        sanshiriweiyongqi += total;

        result.put("collectdevicecount", collectdevicecount + "");
        result.put("monthgascount", b1.doubleValue() + "");
        result.put("yeargascount", b2.doubleValue() + "");
        result.put("七天未上传", sanshiriweishanchuang + "");
        result.put("七天未用气", sanshiriweiyongqi + "");
        result.put("昨日未上传", sanririweishanchuang + "");
        result.put("昨日未用气", sanriweiyongqi + "");
        return new BaseResponse("0", "成功",result);
    }
}
